<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP
           , NoImplicitPrelude
           , BangPatterns
  #-}</span><span>
</span><span id="line-6"></span><span>
</span><span id="line-7"></span><span class="hs-comment">-- ----------------------------------------------------------------------------</span><span>
</span><span id="line-8"></span><span class="hs-comment">--</span><span>
</span><span id="line-9"></span><span class="hs-comment">--  (c) The University of Glasgow 2006</span><span>
</span><span id="line-10"></span><span class="hs-comment">--</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Fingerprints for recompilation checking and ABI versioning, and</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- implementing fast comparison of Typeable.</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- ----------------------------------------------------------------------------</span><span>
</span><span id="line-15"></span><span>
</span><span id="line-16"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Fingerprint</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-17"></span><span>        </span><span class="annot"><a href="GHC.Fingerprint.Type.html#Fingerprint"><span class="hs-identifier">Fingerprint</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Fingerprint.html#fingerprint0"><span class="hs-identifier">fingerprint0</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-18"></span><span>        </span><span class="annot"><a href="GHC.Fingerprint.html#fingerprintData"><span class="hs-identifier">fingerprintData</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-19"></span><span>        </span><span class="annot"><a href="GHC.Fingerprint.html#fingerprintString"><span class="hs-identifier">fingerprintString</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-20"></span><span>        </span><span class="annot"><a href="GHC.Fingerprint.html#fingerprintFingerprints"><span class="hs-identifier">fingerprintFingerprints</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-21"></span><span>        </span><span class="annot"><a href="GHC.Fingerprint.html#getFileHash"><span class="hs-identifier">getFileHash</span></a></span><span>
</span><span id="line-22"></span><span>   </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-23"></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.html"><span class="hs-identifier">GHC.IO</span></a></span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.List.html"><span class="hs-identifier">GHC.List</span></a></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Show.html"><span class="hs-identifier">GHC.Show</span></a></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.html"><span class="hs-identifier">Foreign</span></a></span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.html"><span class="hs-identifier">Foreign.C</span></a></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.IO.html"><span class="hs-identifier">System.IO</span></a></span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Fingerprint.Type.html"><span class="hs-identifier">GHC.Fingerprint.Type</span></a></span><span>
</span><span id="line-35"></span><span>
</span><span id="line-36"></span><span class="hs-comment">-- for SIZEOF_STRUCT_MD5CONTEXT:</span><span class="hs-cpp">
#include &quot;HsBaseConfig.h&quot;
</span><span>
</span><span id="line-39"></span><span class="hs-comment">-- XXX instance Storable Fingerprint</span><span>
</span><span id="line-40"></span><span class="hs-comment">-- defined in Foreign.Storable to avoid orphan instance</span><span>
</span><span id="line-41"></span><span>
</span><span id="line-42"></span><span class="annot"><a href="GHC.Fingerprint.html#fingerprint0"><span class="hs-identifier hs-type">fingerprint0</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Fingerprint.Type.html#Fingerprint"><span class="hs-identifier hs-type">Fingerprint</span></a></span><span>
</span><span id="line-43"></span><span id="fingerprint0"><span class="annot"><span class="annottext">fingerprint0 :: Fingerprint
</span><a href="GHC.Fingerprint.html#fingerprint0"><span class="hs-identifier hs-var hs-var">fingerprint0</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Word64 -&gt; Word64 -&gt; Fingerprint
</span><a href="GHC.Fingerprint.Type.html#Fingerprint"><span class="hs-identifier hs-var">Fingerprint</span></a></span><span> </span><span class="annot"><span class="annottext">Word64
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Word64
</span><span class="hs-number">0</span></span><span>
</span><span id="line-44"></span><span>
</span><span id="line-45"></span><span class="annot"><a href="GHC.Fingerprint.html#fingerprintFingerprints"><span class="hs-identifier hs-type">fingerprintFingerprints</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Fingerprint.Type.html#Fingerprint"><span class="hs-identifier hs-type">Fingerprint</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Fingerprint.Type.html#Fingerprint"><span class="hs-identifier hs-type">Fingerprint</span></a></span><span>
</span><span id="line-46"></span><span id="fingerprintFingerprints"><span class="annot"><span class="annottext">fingerprintFingerprints :: [Fingerprint] -&gt; Fingerprint
</span><a href="GHC.Fingerprint.html#fingerprintFingerprints"><span class="hs-identifier hs-var hs-var">fingerprintFingerprints</span></a></span></span><span> </span><span id="local-6989586621679537695"><span class="annot"><span class="annottext">[Fingerprint]
</span><a href="#local-6989586621679537695"><span class="hs-identifier hs-var">fs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO Fingerprint -&gt; Fingerprint
forall a. IO a -&gt; a
</span><a href="GHC.IO.Unsafe.html#unsafeDupablePerformIO"><span class="hs-identifier hs-var">unsafeDupablePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO Fingerprint -&gt; Fingerprint) -&gt; IO Fingerprint -&gt; Fingerprint
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-47"></span><span>  </span><span class="annot"><span class="annottext">[Fingerprint]
-&gt; (Int -&gt; Ptr Fingerprint -&gt; IO Fingerprint) -&gt; IO Fingerprint
forall a b. Storable a =&gt; [a] -&gt; (Int -&gt; Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Array.html#withArrayLen"><span class="hs-identifier hs-var">withArrayLen</span></a></span><span> </span><span class="annot"><span class="annottext">[Fingerprint]
</span><a href="#local-6989586621679537695"><span class="hs-identifier hs-var">fs</span></a></span><span> </span><span class="annot"><span class="annottext">((Int -&gt; Ptr Fingerprint -&gt; IO Fingerprint) -&gt; IO Fingerprint)
-&gt; (Int -&gt; Ptr Fingerprint -&gt; IO Fingerprint) -&gt; IO Fingerprint
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679537692"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537692"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span id="local-6989586621679537691"><span class="annot"><span class="annottext">Ptr Fingerprint
</span><a href="#local-6989586621679537691"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-48"></span><span>    </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; IO Fingerprint
</span><a href="GHC.Fingerprint.html#fingerprintData"><span class="hs-identifier hs-var">fingerprintData</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Fingerprint -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Fingerprint
</span><a href="#local-6989586621679537691"><span class="hs-identifier hs-var">p</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537692"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Fingerprint -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Fingerprint] -&gt; Fingerprint
forall a. [a] -&gt; a
</span><a href="GHC.List.html#head"><span class="hs-identifier hs-var">head</span></a></span><span> </span><span class="annot"><span class="annottext">[Fingerprint]
</span><a href="#local-6989586621679537695"><span class="hs-identifier hs-var">fs</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-49"></span><span>
</span><span id="line-50"></span><span class="annot"><a href="GHC.Fingerprint.html#fingerprintData"><span class="hs-identifier hs-type">fingerprintData</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Fingerprint.Type.html#Fingerprint"><span class="hs-identifier hs-type">Fingerprint</span></a></span><span>
</span><span id="line-51"></span><span id="fingerprintData"><span class="annot"><span class="annottext">fingerprintData :: Ptr Word8 -&gt; Int -&gt; IO Fingerprint
</span><a href="GHC.Fingerprint.html#fingerprintData"><span class="hs-identifier hs-var hs-var">fingerprintData</span></a></span></span><span> </span><span id="local-6989586621679537686"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679537686"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span id="local-6989586621679537685"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537685"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-52"></span><span>  </span><span class="annot"><span class="annottext">Int -&gt; (Ptr MD5Context -&gt; IO Fingerprint) -&gt; IO Fingerprint
forall a b. Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#allocaBytes"><span class="hs-identifier hs-var">allocaBytes</span></a></span><span> </span><span class="hs-identifier">SIZEOF_STRUCT_MD5CONTEXT</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">pctxt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-53"></span><span>    </span><span class="hs-identifier">c_MD5Init</span><span> </span><span class="hs-identifier">pctxt</span><span>
</span><span id="line-54"></span><span>    </span><span class="hs-identifier">c_MD5Update</span><span> </span><span class="hs-identifier">pctxt</span><span> </span><span class="hs-identifier">buf</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">len</span><span class="hs-special">)</span><span>
</span><span id="line-55"></span><span>    </span><span class="hs-identifier">allocaBytes</span><span> </span><span class="hs-number">16</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">pdigest</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-56"></span><span>      </span><span class="hs-identifier">c_MD5Final</span><span> </span><span class="hs-identifier">pdigest</span><span> </span><span class="hs-identifier">pctxt</span><span>
</span><span id="line-57"></span><span>      </span><span class="hs-identifier">peek</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">castPtr</span><span> </span><span class="hs-identifier">pdigest</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">Fingerprint</span><span class="hs-special">)</span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span class="annot"><a href="GHC.Fingerprint.html#fingerprintString"><span class="hs-identifier hs-type">fingerprintString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Fingerprint.Type.html#Fingerprint"><span class="hs-identifier hs-type">Fingerprint</span></a></span><span>
</span><span id="line-60"></span><span id="fingerprintString"><span class="annot"><span class="annottext">fingerprintString :: String -&gt; Fingerprint
</span><a href="GHC.Fingerprint.html#fingerprintString"><span class="hs-identifier hs-var hs-var">fingerprintString</span></a></span></span><span> </span><span id="local-6989586621679537677"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679537677"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO Fingerprint -&gt; Fingerprint
forall a. IO a -&gt; a
</span><a href="GHC.IO.Unsafe.html#unsafeDupablePerformIO"><span class="hs-identifier hs-var">unsafeDupablePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO Fingerprint -&gt; Fingerprint) -&gt; IO Fingerprint -&gt; Fingerprint
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-61"></span><span>  </span><span class="annot"><span class="annottext">[Word8] -&gt; (Int -&gt; Ptr Word8 -&gt; IO Fingerprint) -&gt; IO Fingerprint
forall a b. Storable a =&gt; [a] -&gt; (Int -&gt; Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Array.html#withArrayLen"><span class="hs-identifier hs-var">withArrayLen</span></a></span><span> </span><span class="annot"><span class="annottext">[Word8]
</span><a href="#local-6989586621679537676"><span class="hs-identifier hs-var">word8s</span></a></span><span> </span><span class="annot"><span class="annottext">((Int -&gt; Ptr Word8 -&gt; IO Fingerprint) -&gt; IO Fingerprint)
-&gt; (Int -&gt; Ptr Word8 -&gt; IO Fingerprint) -&gt; IO Fingerprint
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679537675"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537675"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span id="local-6989586621679537674"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679537674"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-62"></span><span>     </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; IO Fingerprint
</span><a href="GHC.Fingerprint.html#fingerprintData"><span class="hs-identifier hs-var">fingerprintData</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679537674"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537675"><span class="hs-identifier hs-var">len</span></a></span><span>
</span><span id="line-63"></span><span>    </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679537676"><span class="annot"><span class="annottext">word8s :: [Word8]
</span><a href="#local-6989586621679537676"><span class="hs-identifier hs-var hs-var">word8s</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Char -&gt; [Word8]) -&gt; String -&gt; [Word8]
forall a b. (a -&gt; [b]) -&gt; [a] -&gt; [b]
</span><a href="GHC.List.html#concatMap"><span class="hs-identifier hs-var">concatMap</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; [Word8]
forall {a}. Num a =&gt; Char -&gt; [a]
</span><a href="#local-6989586621679537670"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679537677"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-64"></span><span>          </span><span id="local-6989586621679537670"><span class="annot"><span class="annottext">f :: Char -&gt; [a]
</span><a href="#local-6989586621679537670"><span class="hs-identifier hs-var hs-var">f</span></a></span></span><span> </span><span id="local-6989586621679537652"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679537652"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="annot"><a href="#local-6989586621679537651"><span class="hs-identifier hs-type">w32</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Word.html#Word32"><span class="hs-identifier hs-type">Word32</span></a></span><span>
</span><span id="line-65"></span><span>                    </span><span id="local-6989586621679537651"><span class="annot"><span class="annottext">w32 :: Word32
</span><a href="#local-6989586621679537651"><span class="hs-identifier hs-var hs-var">w32</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Word32
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; Int
</span><a href="GHC.Base.html#ord"><span class="hs-identifier hs-var">ord</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679537652"><span class="hs-identifier hs-var">c</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-66"></span><span>                </span><span class="hs-keyword">in</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Word32 -&gt; a
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679537651"><span class="hs-identifier hs-var">w32</span></a></span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; Int -&gt; Word32
forall a. Bits a =&gt; a -&gt; Int -&gt; a
</span><a href="Data.Bits.html#shiftR"><span class="hs-operator hs-var">`shiftR`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">24</span></span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-67"></span><span>                    </span><span class="annot"><span class="annottext">Word32 -&gt; a
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679537651"><span class="hs-identifier hs-var">w32</span></a></span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; Int -&gt; Word32
forall a. Bits a =&gt; a -&gt; Int -&gt; a
</span><a href="Data.Bits.html#shiftR"><span class="hs-operator hs-var">`shiftR`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">16</span></span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-68"></span><span>                    </span><span class="annot"><span class="annottext">Word32 -&gt; a
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679537651"><span class="hs-identifier hs-var">w32</span></a></span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; Int -&gt; Word32
forall a. Bits a =&gt; a -&gt; Int -&gt; a
</span><a href="Data.Bits.html#shiftR"><span class="hs-operator hs-var">`shiftR`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">8</span></span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-69"></span><span>                    </span><span class="annot"><span class="annottext">Word32 -&gt; a
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679537651"><span class="hs-identifier hs-var">w32</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-70"></span><span>
</span><span id="line-71"></span><span class="hs-comment">-- | Computes the hash of a given file.</span><span>
</span><span id="line-72"></span><span class="hs-comment">-- This function loops over the handle, running in constant memory.</span><span>
</span><span id="line-73"></span><span class="hs-comment">--</span><span>
</span><span id="line-74"></span><span class="hs-comment">-- @since 4.7.0.0</span><span>
</span><span id="line-75"></span><span class="annot"><a href="GHC.Fingerprint.html#getFileHash"><span class="hs-identifier hs-type">getFileHash</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Fingerprint.Type.html#Fingerprint"><span class="hs-identifier hs-type">Fingerprint</span></a></span><span>
</span><span id="line-76"></span><span id="getFileHash"><span class="annot"><span class="annottext">getFileHash :: String -&gt; IO Fingerprint
</span><a href="GHC.Fingerprint.html#getFileHash"><span class="hs-identifier hs-var hs-var">getFileHash</span></a></span></span><span> </span><span id="local-6989586621679537647"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679537647"><span class="hs-identifier hs-var">path</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IOMode -&gt; (Handle -&gt; IO Fingerprint) -&gt; IO Fingerprint
forall r. String -&gt; IOMode -&gt; (Handle -&gt; IO r) -&gt; IO r
</span><a href="System.IO.html#withBinaryFile"><span class="hs-identifier hs-var">withBinaryFile</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679537647"><span class="hs-identifier hs-var">path</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#ReadMode"><span class="hs-identifier hs-var">ReadMode</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle -&gt; IO Fingerprint) -&gt; IO Fingerprint)
-&gt; (Handle -&gt; IO Fingerprint) -&gt; IO Fingerprint
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679537644"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679537644"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-77"></span><span>  </span><span class="annot"><span class="annottext">Int -&gt; (Ptr MD5Context -&gt; IO Fingerprint) -&gt; IO Fingerprint
forall a b. Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#allocaBytes"><span class="hs-identifier hs-var">allocaBytes</span></a></span><span> </span><span class="hs-identifier">SIZEOF_STRUCT_MD5CONTEXT</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">pctxt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-78"></span><span>    </span><span class="hs-identifier">c_MD5Init</span><span> </span><span class="hs-identifier">pctxt</span><span>
</span><span id="line-79"></span><span>
</span><span id="line-80"></span><span>    </span><span class="hs-identifier">processChunks</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">buf</span><span> </span><span class="hs-identifier">size</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">c_MD5Update</span><span> </span><span class="hs-identifier">pctxt</span><span> </span><span class="hs-identifier">buf</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">size</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-81"></span><span>
</span><span id="line-82"></span><span>    </span><span class="hs-identifier">allocaBytes</span><span> </span><span class="hs-number">16</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">pdigest</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-83"></span><span>      </span><span class="hs-identifier">c_MD5Final</span><span> </span><span class="hs-identifier">pdigest</span><span> </span><span class="hs-identifier">pctxt</span><span>
</span><span id="line-84"></span><span>      </span><span class="hs-identifier">peek</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">castPtr</span><span> </span><span class="hs-identifier">pdigest</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">Fingerprint</span><span class="hs-special">)</span><span>
</span><span id="line-85"></span><span>
</span><span id="line-86"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-87"></span><span>    </span><span id="local-6989586621679537637"><span class="annot"><span class="annottext">_BUFSIZE :: Int
</span><a href="#local-6989586621679537637"><span class="hs-identifier hs-var hs-var">_BUFSIZE</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">4096</span></span><span>
</span><span id="line-88"></span><span>
</span><span id="line-89"></span><span>    </span><span class="hs-comment">-- | Loop over _BUFSIZE sized chunks read from the handle,</span><span>
</span><span id="line-90"></span><span>    </span><span class="hs-comment">-- passing the callback a block of bytes and its size.</span><span>
</span><span id="line-91"></span><span>    </span><span class="annot"><a href="#local-6989586621679537642"><span class="hs-identifier hs-type">processChunks</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-92"></span><span>    </span><span id="local-6989586621679537642"><span class="annot"><span class="annottext">processChunks :: Handle -&gt; (Ptr Word8 -&gt; Int -&gt; IO ()) -&gt; IO ()
</span><a href="#local-6989586621679537642"><span class="hs-identifier hs-var hs-var">processChunks</span></a></span></span><span> </span><span id="local-6989586621679537636"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679537636"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679537635"><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679537635"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ()
forall a b. Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#allocaBytes"><span class="hs-identifier hs-var">allocaBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537637"><span class="hs-identifier hs-var">_BUFSIZE</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679537634"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679537634"><span class="hs-identifier hs-var">arrPtr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-93"></span><span>
</span><span id="line-94"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679537622"><span class="annot"><span class="annottext">loop :: IO ()
</span><a href="#local-6989586621679537622"><span class="hs-identifier hs-var hs-var">loop</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-95"></span><span>            </span><span id="local-6989586621679537621"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537621"><span class="hs-identifier hs-var">count</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; Ptr Word8 -&gt; Int -&gt; IO Int
forall a. Handle -&gt; Ptr a -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#hGetBuf"><span class="hs-identifier hs-var">hGetBuf</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679537636"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679537634"><span class="hs-identifier hs-var">arrPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537637"><span class="hs-identifier hs-var">_BUFSIZE</span></a></span><span>
</span><span id="line-96"></span><span>            </span><span id="local-6989586621679537619"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679537619"><span class="hs-identifier hs-var">eof</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; IO Bool
</span><a href="GHC.IO.Handle.html#hIsEOF"><span class="hs-identifier hs-var">hIsEOF</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679537636"><span class="hs-identifier hs-var">h</span></a></span><span>
</span><span id="line-97"></span><span>            </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537621"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%2F%3D"><span class="hs-operator hs-var">/=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537637"><span class="hs-identifier hs-var">_BUFSIZE</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679537619"><span class="hs-identifier hs-var">eof</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
forall a. String -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-98"></span><span>              </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;GHC.Fingerprint.getFileHash: only read &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537621"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; bytes&quot;</span></span><span>
</span><span id="line-99"></span><span>
</span><span id="line-100"></span><span>            </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; IO ()
</span><a href="#local-6989586621679537635"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679537634"><span class="hs-identifier hs-var">arrPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679537621"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-101"></span><span>
</span><span id="line-102"></span><span>            </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679537619"><span class="hs-identifier hs-var">eof</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679537622"><span class="hs-identifier hs-var">loop</span></a></span><span>
</span><span id="line-103"></span><span>
</span><span id="line-104"></span><span>      </span><span class="hs-keyword">in</span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679537622"><span class="hs-identifier hs-var">loop</span></a></span><span>
</span><span id="line-105"></span><span>
</span><span id="line-106"></span><span class="hs-keyword">data</span><span> </span><span id="MD5Context"><span class="annot"><a href="GHC.Fingerprint.html#MD5Context"><span class="hs-identifier hs-var">MD5Context</span></a></span></span><span>
</span><span id="line-107"></span><span>
</span><span id="line-108"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;__hsbase_MD5Init&quot;</span></span><span>
</span><span id="line-109"></span><span>   </span><span id="c_MD5Init"><span class="annot"><a href="GHC.Fingerprint.html#c_MD5Init"><span class="hs-identifier hs-var">c_MD5Init</span></a></span></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Fingerprint.html#MD5Context"><span class="hs-identifier hs-type">MD5Context</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-110"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;__hsbase_MD5Update&quot;</span></span><span>
</span><span id="line-111"></span><span>   </span><span id="c_MD5Update"><span class="annot"><a href="GHC.Fingerprint.html#c_MD5Update"><span class="hs-identifier hs-var">c_MD5Update</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Fingerprint.html#MD5Context"><span class="hs-identifier hs-type">MD5Context</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-112"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;__hsbase_MD5Final&quot;</span></span><span>
</span><span id="line-113"></span><span>   </span><span id="c_MD5Final"><span class="annot"><a href="GHC.Fingerprint.html#c_MD5Final"><span class="hs-identifier hs-var">c_MD5Final</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Fingerprint.html#MD5Context"><span class="hs-identifier hs-type">MD5Context</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-114"></span></pre></body></html>